package com.ykdl.member.kid.marketcard;

import java.util.ArrayList;

import net.wxxr.dataparse.model.DataParseError;
import net.wxxr.dataparse.model.DataState;
import net.wxxr.http.interfaces.ITag;
import net.wxxr.http.request.HttpBaseRequest;
import oauth.signpost.http.HttpParameters;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.ykdl.member.constant.KidAction;
import com.ykdl.member.constant.KidConfig;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.beans.ConsigneeBean;
import com.ykdl.member.kid.beans.IntegralDetailsBean;
import com.ykdl.member.kid.beans.Point_typeBean;
import com.ykdl.member.kid.beans.Show_ScoreBean;
import com.ykdl.member.kid.beans.UserActorBean;
import com.ykdl.member.kid.circle.CircleInfoActivity;
import com.ykdl.member.kid.circle.CircleTopicActivity;
import com.ykdl.member.kid.circle.MemberListActivity;
import com.ykdl.member.kid.circle.TopicAndResultActivity;
import com.ykdl.member.kid.gears.BaseScreen;
import com.ykdl.member.kid.image.ImageOptionsFactory;
import com.ykdl.member.kid.widget.AsyncImageView;
import com.ykdl.member.views.MyGridView;
import com.ykdl.net.manager.TaskManager;
import com.ykdl.net.manager.Wxxr;

public class IntegralDetailsActivity extends BaseScreen{
	private MyGridView member_gridview ;
	final int[] navigation_res = { R.drawable.brand_icon_1, R.drawable.brand_icon_2, R.drawable.brand_icon_3, 
			R.drawable.brand_icon_4, R.drawable.brand_icon_5};
	private String point_type_id ;
	private Point_typeBean bean ;
	private TextView card_name,score;
	private BitmapUtils bitmapUtil;
	private ImageView trademark;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		bean = (Point_typeBean) this.getIntent().getSerializableExtra("Point_typeBean");
		setTopTitle(bean.getName()+"积分", 0, R.drawable.back_bg, new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		}, 0,
		0, null, R.drawable.title_bg, false);
		point_type_id = bean.getPoint_type_id();
		setContent(R.layout.integraldetailsactivity_xml);
		bitmapUtil = new BitmapUtils(this);
		bitmapUtil.configDefaultLoadingImage(R.drawable.defult_head_icon);
		bitmapUtil.configDefaultLoadFailedImage(R.drawable.defult_head_icon);
		inint();
		setData(bean);
	}
	public void getData() {
		showProgress("正在加载中,请稍等...");
		String  pageurl =KidConfig.GET_POINTS_SHOW;
		HttpParameters parameterss = new HttpParameters();
		parameterss.put("point_type_id", point_type_id);
		HttpBaseRequest request  =  Wxxr.getInstance().getRequest(pageurl,parameterss);
		 TaskManager.startHttpRequest(request, new getDataTag(),  IntegralDetailsBean.class);
	}
	
	class getDataTag implements ITag {

		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			finishProgress();
			if (t instanceof IntegralDetailsBean) {
				IntegralDetailsBean bean = (IntegralDetailsBean)t;
				if (null==bean.getError()) {
					setData(bean.getPoint_type());
				}else {
					Toast.makeText(mContext, "加载失败,"+bean.getDesc(), 1).show();
				}
				
			}
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "加载失败", 1).show();
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			
		}
		
	}
	public void setData(Point_typeBean bean) {
//		card_name.setText(bean.getName());
		bitmapUtil.display(trademark, bean.getIcon().getFile_url());
		score.setText(bean.getScore());
	}
	public void inint() {
		trademark = (ImageView)findViewById(R.id.trademark);
		score = (TextView)findViewById(R.id.score);
		member_gridview = (MyGridView) findViewById(R.id.member_gridview);
		MemberAdapter adapter = new MemberAdapter();
		member_gridview.setAdapter(adapter);
		member_gridview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(mContext, CardScoreWapActivity.class);
				intent.putExtra(KidAction.POINT_TYPE_ID, point_type_id);
				switch (arg2) {
				case 0:
					intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					intent.putExtra(KidAction.URL_TYPE, 0);
					IntegralDetailsActivity.this.startActivity(intent);
					break;
				case 1:
					Intent intent2=new Intent(mContext, IntegralIotteryActivity.class);
					intent2.putExtra("point_type_id", point_type_id);
					IntegralDetailsActivity.this.startActivity(intent2);
					break;
				case 2:
					intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					intent.putExtra(KidAction.URL_TYPE, 3);
					IntegralDetailsActivity.this.startActivity(intent);
					break;
				case 3:
					intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					intent.putExtra(KidAction.URL_TYPE, 2);
					IntegralDetailsActivity.this.startActivity(intent);
					break;
				case 4:
					intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					intent.putExtra(KidAction.URL_TYPE, 4);
					IntegralDetailsActivity.this.startActivity(intent);
					break;

				default:
					break;
					
				}
				
			}
		});
	}
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		getData();
		super.onResume();
	}
	class MemberAdapter extends BaseAdapter {
		ArrayList<UserActorBean>   list;
		
		public void setList(ArrayList<UserActorBean> list) {
			this.list = list;
		}
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
//			if (list==null) {
//				return 0;
//			}else {
//				return list.size();
//			}
			return navigation_res.length;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			MemberViewHolder holder;
			if (convertView==null) {
				convertView = RelativeLayout.inflate(mContext,
						R.layout.member_gridview_item_xml1, null);
				holder = new MemberViewHolder();
				holder.member_head = (ImageView) convertView.findViewById(R.id.member_head);
				convertView.setTag(holder);
			}else {
				holder = (MemberViewHolder) convertView.getTag();
			}
			holder.member_head.setBackgroundDrawable(getResources().getDrawable(navigation_res[position]));
			return convertView;
		}
		class MemberViewHolder {
			ImageView member_head;
		}

		
	}
}
